package com.example.learnandroid;

import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.LoginFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

public class Customlayout extends DialogFragment {
    private Customlayout.NotifyDialogListener listener;
    EditText username;
    EditText password;


    public interface NotifyDialogListener {
        public void onDialogPositiveClicked(String s, String gender);
    }

    public void setListener(Customlayout.NotifyDialogListener listener) {
        this.listener = listener;
    }


    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = requireActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_signin, null);

        username = view.findViewById(R.id.username);
        password = view.findViewById(R.id.password);

        builder.setView(view)
                .setTitle("自定义对话框")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Toast.makeText(getActivity().getApplicationContext(), "你确定了", Toast.LENGTH_SHORT).show();
                        //listener.onDialogPositiveClicked(username.getText().toString(),password.getText().toString());
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Toast.makeText(getActivity().getApplicationContext(), "你取消了", Toast.LENGTH_SHORT).show();

                    }
                });
        return builder.create();
    }

}
